﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Win32;

namespace mySerialPortHelper
{
    public class AppUtil
    {
        public static List<string> GetSerialCommsList()
        {
            string key = @"HARDWARE\DEVICEMAP\SERIALCOMM";
            List<string> vList = new List<string>();
            RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(key);
            if (registryKey != null)
            {
                string[] registrKeyNames = registryKey.GetValueNames();
                foreach (string registrKeyName in registrKeyNames)
                {
                    string portName = registryKey.GetValue(registrKeyName, null).ToString();
                    vList.Add(portName);
                }
            }
            return vList;
        }

        public static string ConvertStrToHexStr(string s)
        {
            byte[] bytes = Encoding.Default.GetBytes(s);
            string hexString = BitConverter.ToString(bytes);
            return hexString.Replace("-", " ");
        }

        public static string ConvertByteToHexStr(byte[] bytes)
        {
            string hexString = BitConverter.ToString(bytes);
            return hexString.Replace("-", " ");
        }
    }
}
